from flask import abort
from flask import current_app
from flask import request

from info import constants, redis_store
from info.utils.captcha.captcha import captcha
from . import passport_blu

@passport_blu.route('/image_code')
def get_image_code():
    # 生成图片验证码
    #1取到参数
    # 判断参数是否有数值
    #生成图片验证
    # 保存图片验证码文字内容到redis
    #
    image_code_id = request.args.get("imageCodeId",None)
    if not image_code_id:
        return abort(403)

    name,text,image = captcha.generate_capture()
    try:
        redis_store.set("ImageCodeId_"+image_code_id,text,constants.IMAGE_CODE_REDIS_EXPIF)
    except Exception as e:
        current_app.logger.error(e)
        abort(500)
    return image